import React, { Component, Children } from "react";
import Bus from "../bus/bus";

class solt extends Component {
  constructor(props) {
    console.log(props, "====", Children);
    super(props);
    this.state = {
      arr: [],
    };
  }
  componentDidMount() {
    let arr = [];
    React.Children.forEach(this.props.children, (child) => {
      console.log("name =", child);
      arr.push(child);
    });
    this.setState({
      arr,
    });
  }

  render() {
    return (
      <div>
        我是solt
        <div>{this.state.arr}--123</div>
        <div> {Children.only(this.props.children[0])}</div>
        <div> {Children.toArray(this.props.children)}</div>
        <div> {Children.count(this.props.children)}</div>
        {Children.map(this.props.children, function (child) {
          console.log(child, "-------------");
          return <li>{child}</li>;
        })}
        ---------这是跨组件传值 solt
        <Bus></Bus>
      </div>
    );
  }
}

export default solt;
